<template>
  <view>
    <image class="background-image" src="/static/home_background.jpg" mode="aspectFill"></image>
    <text class="text_2 pos_7">内在能力智能管理小程序</text>
  </view>
</template>

<script>
import { getIdentityDefaultTabPage } from '@/util/tabbar.js';

export default {
  data() {
    return {
      open_id: null,
      socketTask: null,
    };
  },
  async mounted() {
    await this.loadUserInfo();
  },

  methods: {
    async loadUserInfo() {
      // 检测是否首次登录
      try {
        const userInfo = await this.$requests.getUserInfo({
          showLoading: true,
        });

        if (userInfo.avatar == "") {
          // 首次登录，填写个人信息
          uni.redirectTo({
            url: "/sub_pages/pages/userinfo/userinfo",
          });
        } else {
          // 非首次登录
          this.$tabbar.switchTab({
            url: getIdentityDefaultTabPage(),
          });
        }
      } catch (e) {
        console.error('获取用户信息失败:', e);
        this.showRetryDialog();
      }
    },

    showRetryDialog() {
      uni.showModal({
        title: '获取用户信息失败',
        content: '网络连接异常，请检查网络后重试',
        showCancel: true,
        cancelText: '退出',
        confirmText: '重试',
        success: (res) => {
          if (res.confirm) {
            // 用户点击重试
            this.loadUserInfo();
          } else if (res.cancel) {
            // 用户点击退出
            uni.showToast({
              title: '请检查网络连接',
              icon: 'none',
              duration: 2000
            });
          }
        }
      });
    }
  },
};
</script>

<style scoped>
.text_2 {
  color: #ffffff;
  font-size: 60rpx;
  font-weight: 700;
  line-height: 58.66rpx;
  text-shadow: 0rpx 8rpx 8rpx #00000040;
}

.pos_7 {
  position: absolute;
  right: 37.42rpx;
  top: 500rpx;
}

.text-wrapper_2 {
  padding: 28rpx 0;
  box-shadow: 0rpx 8rpx 8rpx #00000040;
  background-color: #f26a77;
  border-radius: 40rpx;
  width: 440rpx;
}

.pos_8 {
  position: absolute;
  left: 50%;
  top: 1150rpx;
  transform: translateX(-50%);
}

.text_3 {
  color: #ffffff;
  font-size: 40rpx;
  font-weight: 700;
  line-height: 39.14rpx;
}

.button-hover {
  background-color: #e56571;
}

.background-image {
  position: fixed;
  /* 固定定位 */
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  /* 将背景图片置于底层 */
}
</style>

<style>
page {
  background-size: 100% 100%;
  width: 100%;
  height: 100%;
}
</style>